//package com.topvision.auth.config;
//
//
//import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
//import com.google.common.collect.ImmutableList;
//import com.topvision.common.serialize.CustomBeanSerializerModifier;
//import com.topvision.config.TopvisionProperties;
//import com.topvision.utils.text.JsonMapper;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.env.Environment;
//import org.springframework.http.MediaType;
//import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
//import org.springframework.web.cors.CorsConfiguration;
//import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
//import org.springframework.web.filter.CorsFilter;
//
//import java.util.TimeZone;
//
//
//
//
//@Configuration
//public class WebConfigurer {
//
//    private final Logger log = LoggerFactory.getLogger(WebConfigurer.class);
//
//    private final Environment env;
//
//    private final TopvisionProperties topvisionProperties;
//
//    public WebConfigurer(Environment env, TopvisionProperties topvisionProperties) {
//
//        this.env = env;
//        this.topvisionProperties = topvisionProperties;
//    }
//
//    @Bean
//    public CorsFilter corsFilter() {
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        CorsConfiguration config = topvisionProperties.getCors();
//        if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
//            log.debug("========================================  Registering CORS filter ===============================================================");
//            source.registerCorsConfiguration("/api/**", config);
//            source.registerCorsConfiguration("/v2/api-docs", config);
//        }
//        return new CorsFilter(source);
//    }
//    @Bean
//    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(){
//        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
//
//        JsonMapper jsonMapper = new JsonMapper();
//
//        jsonMapper.setSerializerFactory(jsonMapper.getSerializerFactory().withSerializerModifier(new CustomBeanSerializerModifier()));
//
//        converter.setSupportedMediaTypes(ImmutableList.of(MediaType.TEXT_HTML, MediaType.APPLICATION_JSON));
//
//        jsonMapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
//        jsonMapper.registerModule(new JavaTimeModule());
//
//        converter.setObjectMapper(jsonMapper);
//        return  converter;
//    }
//
//}
